import 'package:flutter/material.dart';
import 'package:homepad/styles.dart';
import 'package:homepad/widgets/home_weather.dart';
import 'package:homepad/widgets/room_sensor.dart';
import 'package:provider/provider.dart';
import 'package:homepad/models/nova_model.dart';
import 'package:homepad/models/datetime_model.dart';
import 'package:homepad/views/item_service_card.dart';

class HomeWidgetMain extends StatelessWidget {
  const HomeWidgetMain({super.key});

  @override
  Widget build(BuildContext context) {
    final MyStyles styles = Theme.of(context).extension<MyStyles>()!;

    var config = context.watch<NovaModel>().config;
    var time = context.watch<DateTimeModel>().time;

    var node1 = config.getPrimaryNode(0);
    var node2 =  config.getPrimaryNode(1);

    return Container(
      height: 470,
      width: 484,
      decoration: ShapeDecoration(
        shape: RoundedRectangleBorder(borderRadius: styles.radius),
        image: const DecorationImage(
          fit: BoxFit.fill,
          image: AssetImage("assets/images/bg_home_widget_main.jpg"),
        ),
      ),
      child: Container(
        color: styles.overlay,
        child: Stack(
          children: [
            Positioned(left: 16, top: -15, child: Text(time, style: styles.homeTimeTextStyle)),
            const Positioned(right: 16, top: 16, child: HomeWeatherWidget()),
            const Positioned(left: 20, top: 140, child: RoomSensorWidget()),
            Positioned(
                bottom: 15,
                left: 15,
                child: Row(
                  children: [
                    if (node1 != null) ItemServiceCard(node: node1),
                    if (node1 != null) const SizedBox(width: 14),
                    if (node2 != null) ItemServiceCard(node: node2),
                  ],
                ))
          ],
        ),
      ),
    );
  }
}